<!--[if lte IE 9]>
<div class="alert alert-warning">
    您的浏览器版本过低, 部分功能将无法使用。<br>
    我们建议您使用最新版本的Chrome浏览器。
</div>
<![endif]-->
<h4>状态</h4>
<table id="status" class="table table-bordered table-striped">
    <thead>
        <tr>
            <th width="25%">Property</th>
            <th>Value</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Total IP / Good IP</td>
            <td id="gws-ip-num"></td>
        </tr>
        <tr>
            <td>10th IP handshake(ms)</td>
            <td id="ip-handshake-10"></td>
        </tr>
        <tr>
            <td>Connected Links (<a href="https://github.com/XX-net/XX-Net/wiki/GoAgent-Connection-status" target="_blank">帮助</a>)</td>
            <td id="connected-link"></td>
        </tr>
        <tr>
            <td>Number of Threads Scaning IPs</td>
            <td id="scan-ip-thread-num"></td>
        </tr>
        <tr>
            <td>Block Status (<a href="https://github.com/XX-net/XX-Net/wiki/GoAgent-Blocked" target="_blank">帮助</a>)</td>
            <td id="block-stat"></td>
        </tr>
    </tbody>
</table>

<h4>设置</h4>
<table id="setting" class="table table-bordered table-striped">
    <thead>
        <tr>
            <th width="25%">Property</th>
            <th>Value</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Proxy Listen</td>
            <td id="proxy-listen"></td>
        </tr>
        <tr>
            <td>PAC URL</td>
            <td id="pac-url"></td>
        </tr>
        <tr>
            <td>IPv6</td>
            <td id="ipv6-status"></td>
        </tr>
    </tbody>
</table>

<h4>Appid</h4>
<table id="appids" class="table table-bordered table-striped">
    <thead>
        <tr>
            <th width="25%">Property</th>
            <th width="75%">Value</th>
        </tr>
    </thead>
    <tbody>
        <tr hidden="true">
            <td>Set App IDs</td>
            <td id="gae-appid"></td>
        </tr>
        <tr>
            <td>Working App IDs</td>
            <td id="working-appid"></td>
        </tr>
        <tr>
            <td>Out of Quota App IDs</td>
            <td id="out-of-quota-appids"></td>
        </tr>
        <tr>
            <td>Not Exist App IDs</td>
            <td id="not-exist-appids"></td>
        </tr>
    </tbody>
</table>

<h4>系统版本</h4>
<table id="version" class="table table-bordered table-striped">
    <thead>
        <tr>
            <th width="25%">Property</th>
            <th >Value</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>XX-Net Version</td>
            <td id="xxnet-version"></td>
        </tr>
        <tr>
            <td>Python Version</td>
            <td id="python-version"></td>
        </tr>
        <tr>
            <td>System Platform</td>
            <td id="sys-platform"></td>
        </tr>
        <tr>
            <td>OS System</td>
            <td id="os-system"></td>
        </tr>
        <tr>
            <td>OS Version</td>
            <td id="os-version"></td>
        </tr>
        <tr>
            <td>OS Release</td>
            <td id="os-release"></td>
        </tr>
        <tr>
            <td>OS Detail</td>
            <td id="os-detail"></td>
        </tr>
        <tr>
            <td>Language</td>
            <td id="language"></td>
        </tr>
        <tr>
            <td>Architecture</td>
            <td id="architecture"></td>
        </tr>
        <tr>
            <td>Browser</td>
            <td id="browser"></td>
        </tr>
    </tbody>
</table>
<button id="pop-up-report" class="btn btn-primary">反馈问题</button>

<div id="report-issue-modal" class="modal hide fade">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3>诊断信息</h3>
    </div> <!-- .modal-header -->
    <div class="modal-body">
        <p> * 一键反馈需要登录Github账号</p>
        <textarea id="DiagInfo" onmouseover="this.focus();this.select()"></textarea>
    </div>
    <div class="modal-footer">
        <a href="https://groups.google.com/forum/#!forum/xx-net"  id="go-to-goole-group" class="btn btn-primary " target="_blank">前往论坛</a>
        <a href="https://github.com/XX-net/XX-Net/issues"  id="one-key-issue" class="btn btn-success " target="_blank">一键反馈</a>
    </div> <!-- .modal-footer -->
</div> <!-- #report-issue-modal -->

<!-- JavaScript -->
<script type="text/javascript">
    title('GAEProxy状态信息');
</script>
<script type="text/javascript">
    $(function() {
        var timer = $.timer(function() {
            getStatus();
        });

        timer.set({
            time: 1000,
            autostart: true
        });
    });
    function OneKeyReport(){
        $.ajax({
            type: 'GET',
            url: '/module/gae_proxy/control/status',
            dataType: 'JSON',
            success: function(result) {
                var information = new Array('sys-platform: ' + result['sys_platform'], 
                    'os-system: ' + result['os_system'],
                    'os-version: ' + result['os_version'], 
                    'os-release: ' + result['os_release'],
                    'os-detail: ' + result['os_detail'], 
                    'architecture: ' + String(result['architecture'].concat()), 
                    'browser: ' + result['browser'], 
                    'xxnet-version: ' + result['xxnet_version'], 
                    'python-version: ' + result['python_version'], 
                    '\nipv6-status: ' + result['use_ipv6'], 
                    'gws-ip-num: ' + result['gws_ip_num'], 
                    'connected-link: ' + result['connected_link'], 
                    'scan-ip-thread-num: ' + result['scan_ip_thread_num'], 
                    'ip-handshake-10: ' + result['ip_handshake_10'], 
                    'block-stat: ' + result['block_stat'], 
                    'Appid_Working: ' + (result['working_appid'].length != 0), 
                    'Appids_Out_Of_Quota: ' + (result['out_of_quota_appids'].length != 0), 
                    'Appids_Not_Exist: ' + (result['not_exist_appids'].length != 0), 
                    'Using_Public_Appid: ' + (result['gae_appid'].match('xxnet-') != null));
                updateStatus("textarea#DiagInfo","XX-Net Status：\n\n" + information.join("\n"));
                IssueURL = "https://github.com/XX-net/XX-Net/issues/new?body=-----------%0A问题描述：%0A请在此描述你遇到的问题，必要时贴出相关的日志信息。%0A%0A-----------%0A诊断信息：%0A" + encodeURIComponent(information.join("\n")) + ";";
                $("a#one-key-issue").attr("href",IssueURL);
                GGroupURL = "https://groups.google.com/forum/#!forum/xx-net";
                //有待设计类似Github Issue的一键生成功能;
                $("a#go-to-goole-group").attr("href", GGroupURL);
            }
          })
    }
</script>
<script type="text/javascript">
    $(function() {
        getStatus();
    });
    $(document).ready(function(){
        $("#pop-up-report").click(function(){
            OneKeyReport();
            $('#report-issue-modal').modal();
        });
    });
</script>
<script type="text/javascript">
    function updateStatus(selector, content) {
        var previousContent = $(selector).html();
        if (String(previousContent) != String(content)) {
            $(selector).html(content);
        }
    }
    function getStatus() {
        $.ajax({
            type: 'GET',
            url: '/module/ossftp/control/status',
            dataType: 'JSON',
            success: function(result) {
                var updates = {
                    '#sys-platform': result['sys_platform'],
                    '#os-system': result['os_system'],
                    '#os-version': result['os_version'],
                    '#os-release': result['os_release'],
                    '#os-detail': result['os_detail'],
                    '#language': result['language'],
                    '#architecture': String(result['architecture'].concat()),
                    '#browser': result['browser'],
                    '#xxnet-version': result['xxnet_version'],
                    '#python-version': result['python_version'],
                    '#proxy-listen': result['proxy_listen'],
                    '#pac-url': result['pac_url'],
                    '#ipv6-status': result['use_ipv6'] == '0' ? 'Disabled' : 'Enabled',
                    '#gws-ip-num': result['gws_ip_num'],
                    '#connected-link': result['connected_link'],
                    '#gae-appid': result['gae_appid'],
                    '#working-appid': result['working_appid'],
                    '#out-of-quota-appids': result['out_of_quota_appids'],
                    '#not-exist-appids': result['not_exist_appids'],
                    '#scan-ip-thread-num': result['scan_ip_thread_num'],
                    '#ip-handshake-10': result['ip_handshake_10'],
                    '#block-stat': result['block_stat'],
                }
                for (var item in updates) {
                    updateStatus(item, updates[item]);
                }
                if ( !tipHasClose() ) {
                    tipClose();
                }
            },
            error: function(result) {
                var formValue = $('#sys-platform').html();

                if ( tipHasClose() ) {
                    $('html, body').animate({
                        scrollTop: 0
                    }, 'slow');
                }

                if ( formValue == '' ) {
                    tip('状态页显示空白, 很可能GAEProxy启动失败, 请按<a href="https://github.com/XX-net/XX-Net/wiki/How-to-get-start-error-log" target="_blank">指引</a>查找问题原因.<br>', 'warning', false);
                } else {
                    tip('GAEProxy进程无响应, 可能已退出.', 'warning', false);
                }
            }
        });
    }
</script>
